main() {
  print("hello world");

  Future.delayed(Duration(seconds: 2), () {
        return 'hi world';
        // throw AssertionError("Error");
      })
      .then(
        (data) {
          print(data);
        },
        onError: (e) {
          print(e);
          print("onError");
        },
      )
      .catchError((e) {
        print(e);
      })
      .whenComplete(() {
        print("comlpete");
      });

  Future.wait([
    Future.delayed(Duration(seconds: 2), () {
      return 'hello';
    }),
    Future.delayed(Duration(seconds: 4), () {
      return ' world';
    }),
  ]).then((results) {
    print(results[0] + results[1]);
  });

  Stream.fromFutures([
    Future.delayed(Duration(seconds: 1), () {
      return "hello 1";
    }),
    Future.delayed(Duration(seconds: 2), () {
      throw AssertionError("Error");
    }),
    Future.delayed(Duration(seconds: 3), () {
      return "hello 3";
    }),
  ]).listen(
    (data) {
      print(data);
    },
    onError: (e) {
      print(e.message);
    },
    onDone: () {},
  );
}
